package com.audaque.springboot.foshanupload.rocketmq.config;

import org.apache.rocketmq.client.apis.ClientConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class ClientConfig {

    @Value("${rocketmqProxyHost}")
    private String rocketmqProxyHost;

    @Value("${rocketmqProxyPort}")
    private String rocketmqProxyPort;


    @Value("${rocketmqInvisibleSecond}")
    private Long rocketmqInvisibleSecond;


    @Bean
    public  ClientConfiguration clientConfiguration() {
        // This parameter is necessary only when the server ACL is enabled. Otherwise,
        // it does not need to be set by default.
        //SessionCredentialsProvider sessionCredentialsProvider = new StaticSessionCredentialsProvider(ACCESS_KEY, SECRET_KEY);
        // 接入点地址，需要设置成 Proxy 的地址和端口列表，一般是xxx:8081
        String endpoint = rocketmqProxyHost.concat(":").concat(rocketmqProxyPort);
        ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder()
                .setEndpoints(endpoint)
                .setRequestTimeout(Duration.ofSeconds(rocketmqInvisibleSecond))
                // On some Windows platforms, you may encounter SSL compatibility issues. Try turning off the SSL option in
                // client configuration to solve the problem please if SSL is not essential.
                // .enableSsl(false)
                //.setCredentialProvider(sessionCredentialsProvider)
                .build();
        return clientConfiguration;
    }
}
